/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//http://stackoverflow.com/questions/2508704/how-to-draw-a-circle-in-java-with-a-radius-and-points-around-the-edge




//The parametric equation for a circle is
//
//x = cx + r * cos(a)
//y = cy + r * sin(a)
//
//Where r is the radius, cx,cy the origin, and a the angle from 0..2PI radians or 0..360 degrees.
//
//

//Der går 2π (omkring 6,283185) radianer på en hel cirkel. Én radian er lig 
//med 180/π grader eller ca. 57,29578°. Buen på cirkelperiferien
//der udspændes af en radian er lig radius af cirklen (se figur).
// Formlen for omregning er altså:  radianer = (2π/360) * grader





package jogl2.pkg0.project;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Peb
 */
public class CircleTest_pber extends JPanel {

    private static final int SIZE = 256;
    private int a = SIZE / 2;
    private int b = a;
    private int r = 4 * SIZE / 5;
    private int n;

    /** @param n  the desired number of circles. */
    public CircleTest_pber(int n) {
        super(true);
        this.setPreferredSize(new Dimension(SIZE, SIZE));
        this.n = n;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setBackground(Color.black);
        g2d.setColor(Color.white);
        
        
        a = getWidth() / 2;
        b = getHeight() / 2;
        int m = Math.min(a, b);
        r = 4 * m / 5;
        int r2 = Math.abs(m - r) / 2;
        g2d.drawOval(a - r, b - r, 2 * r, 2 * r);
        g2d.setColor(Color.white);
        for (int i = 0; i < n; i++) {
            
// Formlen for omregning er altså:  radianer = (2π/360) * grader
            
            double t = 2 * Math.PI * i / n;
            
            
            int x = (int) Math.round(100 + r * Math.cos(t));
            int y = (int) Math.round(100 + r * Math.sin(t));
//            g2d.fillOval(x - r2, y - r2, 2 * r2, 2 * r2);
            
            
            g2d.drawLine(x - r2, y - r2, x - r2 +1, y - r2+1);

        }
    }

    private static void create() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new CircleTest_pber(9));
        
        f.pack();
        f.setVisible(true);
        f.setBackground(Color.black);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                create();
            }
        });
    }
}
